#update trading daily from cafef
import MySQLdb
import os
import glob
import common
import cafef

#  1. connect mysql
db = MySQLdb.connect(host="localhost", port=3306, user="root",
                     passwd="123456", db="quant_data", charset='utf8')
cursor=db.cursor()

mydir = './cafef'

## Download and Unzip
#cafef.DownloadAndUnzipCafef(mydir)

os.chdir(mydir)             #change to current dir
files = glob.glob("*.csv")  #find all file with csv extension in current dir
for ffile in files:
    cafef.ImportTradingDailyFrom(ffile)
    
        
cursor.close()  #close the cursor
db.commit()     #commit, must have or else the databases won't change
db.close()      #close the connection
print "\nDONE IMPORT !"
